home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / graphics / mktil16a.zip / MKTIL16.C < prev    next >
C/C++ Source or Header  |  1994-09-19  |  25KB  |  874 lines

  1. #include <stdio.h>
  2. #include <graph.h>
  3. #include <conio.h>
  4. #include <malloc.h>
  5. #include <string.h>
  6. #include <dos.h>
  7. #include <time.h>
  8.  
  9. #define byte unsigned char
  10. #define word unsigned int
  11. #define d_word unsigned long
  12.  
  13. #define OFF 0
  14. #define ON 1
  15.  
  16. #define FAILURE 0
  17. #define SUCCESS 1
  18.  
  19. char path[]={""};
  20.  
  21. #define goto(x,y) _settextposition(y,x)
  22. #define rnd(n) ((rand() % (int)(((n)+1) - (1))) + (1))
  23.  
  24. #include "font.h"
  25. #include "graphics.h"
  26. #include "palette.h"
  27. #include "text.h"
  28. #include "mouse.h"
  29.  
  30. #define TILES 256
  31. #define TILE_X 16
  32. #define TILE_Y 16
  33.  
  34. /****************************************************************************
  35. function prototypes
  36. ****************************************************************************/
  37.  
  38. void set_screen(void);
  39. byte allocate_memory(void);
  40.  
  41. byte allocate_tile(void);
  42. void free_tile(void);
  43.  
  44. void free_memory(void);
  45.  
  46. void init_mouse(void);
  47. void hide_object(void);
  48. void show_object(byte);
  49.  
  50. byte tile_color(byte, int, int);
  51. void update_tile_grid(byte);
  52. void update_tile(int, int, byte, byte);
  53. void update_tile_display(byte, byte);
  54.  
  55. byte load(char *);
  56. byte save(char *);
  57.  
  58. void hide_cursor(byte, int, int);
  59. void show_cursor(byte, int, int);
  60. void hide_color(byte);
  61. void show_color(byte);
  62. void show_palette_information(byte);
  63.  
  64. void hflip(byte);
  65. void vflip(byte);
  66. void rotate(byte);
  67.  
  68. /****************************************************************************
  69. global variables
  70. ****************************************************************************/
  71.  
  72. char palette_file[]={"mode13h"};
  73. char font_file[]={"fnt8-8"};
  74.  
  75. byte huge **tile;
  76. char tile_file[]={"til16-16"};
  77. byte map[64];
  78. char map_file[]={"map8-8"};
  79.  
  80. byte huge *object_background;
  81.  
  82. /****************************************************************************/
  83.  
  84. void main(void)
  85. {
  86.  int x=0, y=0;
  87.  byte current_tile=0, current_color=7;
  88.  int a, b;
  89.  int key=0;
  90.  int tmp;
  91.  
  92.  byte current_page=0;
  93.  byte object=OFF, object_carried;
  94.  byte palette_rotation=ON;
  95.  
  96.  byte compressed=OFF;
  97.  
  98. /****************************************************************************/
  99.  
  100.  srand((unsigned)time);
  101.  
  102.  if (allocate_memory()==FAILURE) goto END;
  103.  
  104.  if (read_font(font_file)==FAILURE) goto END;
  105.  
  106. /****************************************************************************/
  107.  
  108.  _setvideomode(_MRES256COLOR);
  109.  if (read_palette(palette_file)==SUCCESS)
  110.   set_palette();
  111.  
  112.  set_screen();
  113.  
  114.  init_mouse();
  115.  show_cursor(current_tile,x,y);
  116.  show_color(current_color);
  117.  
  118. /****************************************************************************/
  119.  
  120.  do
  121.  {
  122.   memcpy(SCREEN,screen,(size_t)64000);
  123.   hide_mouse();
  124.   hide_cursor(current_tile,x,y);
  125.   hide_color(current_color);
  126.   if (object)
  127.    hide_object();
  128.  
  129.   show_palette_information(current_color);
  130.   if (palette_rotation) palette_switch(248,8);
  131.  
  132.   if (mouse_1)
  133.   {
  134.    ftime(&time_pointer);
  135.    if (mouse_timer<max_mouse_timer)
  136.    {
  137.     mouse_timer+=(d_word)((time_pointer.time*1000+time_pointer.millitm)
  138.          -old_mouse_timer);
  139.     goto END_MOUSE_CLICK;
  140.    }
  141.  
  142.    old_mouse_timer=(d_word)(time_pointer.time*1000+time_pointer.millitm);
  143.    max_mouse_timer=(d_word)(mouse_timer+PALETTE_TIMER);
  144.  
  145.    if (mouse_x>=4 && mouse_x<132 && mouse_y>=4 && mouse_y<132)
  146.    {
  147.     update_tile((mouse_x-4)/8,(mouse_y-4)/8,current_tile,current_color);
  148.    }
  149.    else if (mouse_x>=195 && mouse_x<307 && mouse_y>=180 && mouse_y<196)
  150.    {
  151.     if (object==ON)
  152.     {
  153.      /* copy */
  154.      for (a=0;a<256;a++)
  155.      {
  156.       tile[current_page+(mouse_x-195)/16][a]=tile[object_carried][a];
  157.      }
  158.      update_tile_grid(current_tile);
  159.      object=OFF;
  160.     }
  161.     else
  162.     {
  163.      object=ON;
  164.      object_carried=current_page+(mouse_x-195)/16;
  165.     }
  166.    }
  167.    else if (mouse_x>=188 && mouse_x<316 && mouse_y>=4 && mouse_y<132)
  168.    {
  169.     if (object)
  170.     {
  171.      map[(mouse_y-4)/16*8+(mouse_x-188)/16]=object_carried;
  172.      object=OFF;
  173.     }
  174.     else
  175.     {
  176.      object=ON;
  177.      object_carried=map[(mouse_y-4)/16*8+(mouse_x-188)/16];
  178.     }
  179.    }
  180.    else if (mouse_x>=4 && mouse_x<132 && mouse_y>=136 && mouse_y<200)
  181.    {
  182.     mouse_x-=4; mouse_y-=136;
  183.     current_color=(mouse_y/8)*32+(mouse_x/4);
  184.    }
  185.    else if (mouse_x>=142 && mouse_x<150 && mouse_y>=134 && mouse_y<198)
  186.    {
  187.     /* rem adjust red hue of current color */
  188.     palette[current_color*3+0]=(byte)(197-mouse_y);
  189.     set_palette();
  190.    }
  191.    else if (mouse_x>=156 && mouse_x<164 && mouse_y>=134 && mouse_y<198)
  192.    {
  193.     /* rem adjust green hue of current color */
  194.     palette[current_color*3+1]=(byte)(197-mouse_y);
  195.     set_palette();
  196.    }
  197.    else if (mouse_x>=170 && mouse_x<178 && mouse_y>=134 && mouse_y<198)
  198.    {
  199.     /* rem adjust blue hue of current color */
  200.     palette[current_color*3+2]=(byte)(197-mouse_y);
  201.     set_palette();
  202.    }
  203.    else if (mouse_x>=136 && mouse_x<184 && mouse_y>=68 && mouse_y<76)
  204.    {
  205.     for (a=0;a<256;a++)
  206.      tile[current_tile][a]=0;
  207.     update_tile_grid(current_tile);
  208.    }
  209.    else if (mouse_x>=136 && mouse_x<184 && mouse_y>=76 && mouse_y<84)
  210.    {
  211.     rotate(current_tile);
  212.     update_tile_grid(current_tile);
  213.    }
  214.    else if (mouse_x>=136 && mouse_x<184 && mouse_y>=84 && mouse_y<92)
  215.    {
  216.     hflip(current_tile);
  217.     update_tile_grid(current_tile);
  218.    }
  219.    else if (mouse_x>=136 && mouse_x<184 && mouse_y>=92 && mouse_y<100)
  220.    {
  221.     vflip(current_tile);
  222.     update_tile_grid(current_tile);
  223.    }
  224.    else if (mouse_x>=136 && mouse_x<184 && mouse_y>=100 && mouse_y<108)
  225.    {
  226.      for (a=0;a<256;a++)
  227.       tile[current_tile][a]=(current_color+rnd(4)-rnd(4));
  228.     update_tile_grid(current_tile);
  229.    }
  230.    else if (mouse_x>=188 && mouse_x<195 && mouse_y>=180 && mouse_y<196)
  231.    {
  232.     current_tile--; if (current_tile==255) current_tile=0;
  233.     update_tile_grid(current_tile);
  234.     if (current_tile<current_page)
  235.     {
  236.      current_page--;
  237.     }
  238.    }
  239.    else if (mouse_x>=308 && mouse_x<316 && mouse_y>=180 && mouse_y<196)
  240.    {
  241.     current_tile++; if (current_tile==0) current_tile=255;
  242.     update_tile_grid(current_tile);
  243.     if (current_tile>current_page+6)
  244.     {
  245.      current_page++;
  246.     }
  247.    }
  248.   }
  249.   if (mouse_2)
  250.   {
  251.    ftime(&time_pointer);
  252.    if (mouse_timer<max_mouse_timer)
  253.    {
  254.     mouse_timer+=(d_word)((time_pointer.time*1000+time_pointer.millitm)
  255.          -old_mouse_timer);
  256.     goto END_MOUSE_CLICK;
  257.    }
  258.  
  259.    old_mouse_timer=(d_word)(time_pointer.time*1000+time_pointer.millitm);
  260.    max_mouse_timer=(d_word)(mouse_timer+PALETTE_TIMER);
  261.  
  262.    if (mouse_x>=4 && mouse_x<132 && mouse_y>=4 && mouse_y<132)
  263.    {
  264.     current_color=tile[current_tile][(mouse_y-4)/8*TILE_X+(mouse_x-4)/8];
  265.    }
  266.    else if (mouse_x>=188 && mouse_x<316 && mouse_y>=4 && mouse_y<132)
  267.    {
  268.     current_tile=map[(mouse_y-4)/16*8+(mouse_x-188)/16];
  269.     if (current_tile<current_page) current_page=current_tile;
  270.     else if (current_tile>current_page+6)
  271.     {
  272.      current_page=current_tile-6;
  273.      if (current_page>TILES-7) current_page=TILES-7;
  274.     }
  275.     update_tile_display(current_tile,current_page);
  276.     update_tile_grid(current_tile);
  277.    }
  278.    else if (mouse_x>=195 && mouse_x<307 && mouse_y>=180 && mouse_y<196)
  279.    {
  280.     current_tile=current_page+(mouse_x-195)/16;
  281.     update_tile_display(current_tile,current_page);
  282.     update_tile_grid(current_tile);
  283.    }
  284.   }
  285. END_MOUSE_CLICK:;
  286.  
  287.   if (kbhit())
  288.   {
  289.    key=getch();
  290.    if (key==0)
  291.    {
  292.     key=getch();
  293.     switch(key)
  294.     {
  295.      case 0x48:y--;break;
  296.      case 0x50:y++;break;
  297.      case 0x4B:x--;break;
  298.      case 0x4D:x++;break;
  299.      case 0x49:current_page--;if (current_page==255) current_page=0;break;
  300.      case 0x51:current_page++;if (current_page>249) current_page=249;break;
  301.     }
  302.     if (x<0) x=TILE_X-1;
  303.     else if (x>=TILE_X) x=0;
  304.     if (y<0) y=TILE_Y-1;
  305.     else if (y>=TILE_Y) y=0;
  306.    }
  307.    else
  308.    {
  309.     switch(key)
  310.     {
  311.      case ' ':update_tile(x,y,current_tile,current_color);break;
  312.      case '=':
  313.      case '+':show_palette_information(++current_color);break;
  314.      case '-':show_palette_information(--current_color);break;
  315.      case '.':
  316.      case '>':current_tile++;if (current_tile==0) current_tile=255;
  317.           update_tile_grid(current_tile);break;
  318.      case ',':
  319.      case '<':current_tile--;if (current_tile==255) current_tile=0;
  320.           update_tile_grid(current_tile);break;
  321.      case 'l':load(tile_file);read_palette(palette_file);
  322.           update_tile_grid(current_tile);break;
  323.      case 's':save(tile_file);write_palette(palette_file);break;
  324.      case 'z':for (a=0;a<256;a++)
  325.           {
  326.            tile[current_tile][a]=(current_color+rnd(4)-rnd(4));
  327.           }
  328.           update_tile_grid(current_tile);
  329.           break;
  330.      case 'p':if (palette_rotation) palette_rotation=OFF;
  331.           else palette_rotation=ON; break;
  332.      case 'h':hflip(current_tile);update_tile_grid(current_tile);break;
  333.      case 'v':vflip(current_tile);update_tile_grid(current_tile);break;
  334.      case 'r':rotate(current_tile);update_tile_grid(current_tile);break;
  335.      case 'f':for (a=0;a<256;a++) tile[current_tile][a]=current_color;
  336.           update_tile_grid(current_tile);break;
  337.      case 'g':current_color=tile[current_tile][y*TILE_X+x];break;
  338.     }
  339.     if (current_tile<current_page)
  340.     {
  341.      current_page--;
  342.     }
  343.     else if (current_tile>current_page+6)
  344.     {
  345.      current_page++;
  346.     }
  347.    }
  348.   }
  349.  
  350.  read_mouse();
  351.  
  352.  update_tile_display(current_tile,current_page);
  353.  put_string(160,28,"   ",4,INVERSE);
  354.  put_number_i(160,28,x,7,NORMAL);
  355.  put_string(160,44,"   ",4,INVERSE);
  356.  put_number_i(160,44,y,7,NORMAL);
  357.  
  358.  put_string(136,116,"      ",4,INVERSE);
  359.  put_string(160,60,"   ",4,INVERSE);
  360.  if (compressed)
  361.  {
  362.   put_string(136,116,"cmp",7,NORMAL);
  363.  }
  364.  else
  365.  {
  366.   put_string(136,116,"uncmp",7,NORMAL);
  367.   put_number_i(160,60,TILE_X*TILE_Y,7,NORMAL);
  368.  }
  369.  
  370.  show_cursor(current_tile,x,y);
  371.  show_color(current_color);
  372.  
  373.  if (object)
  374.   show_object(object_carried);
  375.  
  376.  update_mouse();
  377.  
  378.  } while (key!=27);
  379.  
  380. /****************************************************************************/
  381. DONE:;
  382.  _setvideomode(_DEFAULTMODE);
  383.  
  384. /****************************************************************************/
  385. END:;
  386.  free_memory();
  387.  
  388. }
  389.  
  390. /****************************************************************************/
  391. /****************************************************************************/
  392. /****************************************************************************/
  393.  
  394. void set_screen(void)
  395. {
  396.  int a, b;
  397.  
  398. /* rem fill screen with brown (76) pattern */
  399.  
  400.  _setcolor(76);
  401.  _rectangle(_GFILLINTERIOR,0,0,319,199);
  402.  _setcolor(75);
  403.  _rectangle(_GFILLINTERIOR,1,1,318,202);
  404.  
  405. /* setup individual windows */
  406.  
  407.  _setcolor(73);
  408.  _rectangle(_GBORDER,3,3,132,132);
  409.  _rectangle(_GBORDER,135,3,184,132);
  410.  _rectangle(_GBORDER,187,3,316,132);
  411.  _rectangle(_GBORDER,187,135,316,200);
  412.  _rectangle(_GBORDER,3,135,132,200);
  413.  
  414.  _setcolor(74);
  415.  _rectangle(_GBORDER,2,2,133,133);
  416.  _rectangle(_GBORDER,134,2,185,133);
  417.  _rectangle(_GBORDER,186,2,317,133);
  418.  _rectangle(_GBORDER,186,134,317,201);
  419.  _rectangle(_GBORDER,2,134,133,201);
  420.  
  421. /* setup palette bar */
  422.  
  423.  for (b=0;b<8;b++)
  424.  {
  425.   for (a=0;a<32;a++)
  426.   {
  427.    _setcolor(75);
  428.    _rectangle(_GBORDER,a*4+4,b*8+136,a*4+7,b*8+143);
  429.    _setcolor(b*32+a);
  430.    _rectangle(_GFILLINTERIOR,a*4+5,b*8+137,a*4+6,b*8+142);
  431.   }
  432.  }
  433.  
  434. /* setup palette-information bars */
  435.  
  436.  _setcolor(74);
  437.  _rectangle(_GFILLINTERIOR,134,134,185,199);
  438.  _setcolor(0);
  439.  _rectangle(_GFILLINTERIOR,142,135,149,198);
  440.  _rectangle(_GFILLINTERIOR,156,135,163,198);
  441.  _rectangle(_GFILLINTERIOR,170,135,177,198);
  442.  _setcolor(75);
  443.  _rectangle(_GBORDER,141,134,150,199);
  444.  _rectangle(_GBORDER,155,134,164,199);
  445.  _rectangle(_GBORDER,169,134,178,199);
  446.  
  447. /* setup tile drawing grid */
  448.  
  449.  _setcolor(0);
  450.  _rectangle(_GFILLINTERIOR,4,4,131,131);
  451.  
  452.  _setcolor(73);
  453.  for (a=0;a<16;a++)
  454.  {
  455.   _moveto(a*8+4,4);
  456.   _lineto(a*8+4,131);
  457.  }
  458.  for (b=0;b<16;b++)
  459.  {
  460.   _moveto(4,b*8+4);
  461.   _lineto(131,b*8+4);
  462.  }
  463.  
  464. /* setup text info area(s) */
  465.  
  466.  _setcolor(4);
  467.  _rectangle(_GFILLINTERIOR,136,4,136+47,4+127);
  468.  _rectangle(_GFILLINTERIOR,188,136,188+127,136+63);
  469.  
  470. /* setup 8x8 tile display area */
  471.  
  472.  _setcolor(0);
  473.  _rectangle(_GFILLINTERIOR,188,4,315,131);
  474.  
  475. /* setup 7 tile wide selection area */
  476.  
  477.  _setcolor(73);
  478.  _rectangle(_GBORDER,194,179,307,196);
  479.  _setcolor(74);
  480.  _rectangle(_GBORDER,193,178,308,197);
  481.  _setcolor(75);
  482.  _rectangle(_GBORDER,192,177,309,198);
  483.  
  484.  _setcolor(0);
  485.  _rectangle(_GFILLINTERIOR,195,180,306,195);
  486.  
  487. /* copy video to screen-buffer */
  488.  
  489.  memcpy(screen,SCREEN,(size_t)64000);
  490.  
  491. /* setup text entries */
  492.  
  493.  put_string(136,4,"tile",7,NORMAL);
  494.  put_string(136,20,"x",7,NORMAL);
  495.  put_string(136,36,"y",7,NORMAL);
  496.  put_string(136,52,"size",7,NORMAL);
  497.  put_string(136,68,"clear",7,NORMAL);
  498.  put_string(136,76,"rotate",7,NORMAL);
  499.  put_string(136,84,"flip h",7,NORMAL);
  500.  put_string(136,92,"flip v",7,NORMAL);
  501.  put_string(136,100,"z_fill",7,NORMAL);
  502. /* put_string(136,116,"u/cmp",7,NORMAL); */
  503. /* put_string(136,124,"file",7,NORMAL); */
  504.  
  505.  put_string(208,136,"Tile Editor",7,NORMAL);
  506.  put_string(188,152,"filename",7,NORMAL);
  507.  put_string(188,168,"filesize",7,NORMAL);
  508.  
  509.  put_string(252,160,tile_file,7,NORMAL);
  510.  
  511.  
  512. }
  513.  
  514. /****************************************************************************/
  515. /****************************************************************************/
  516. /****************************************************************************/
  517.  
  518. byte allocate_tile(void)
  519. {
  520.  int a;
  521.  
  522.  tile=(byte huge **)halloc((long)TILES,4);
  523.  if (tile==NULL)
  524.  {
  525.   printf("error allocating tile pointers\n");
  526.   return(FAILURE);
  527.  }
  528.  
  529.  for (a=0;a<TILES;a++)
  530.  {
  531.   tile[a]=(byte huge *)halloc((long)(TILE_X*TILE_Y),1);
  532.   if (tile[a]==NULL)
  533.   {
  534.    printf("error allocating tile %3d\n",a);
  535.    return(FAILURE);
  536.   }
  537.  }
  538.  return(SUCCESS);
  539. }
  540.  
  541. /****************************************************************************/
  542. /****************************************************************************/
  543. /****************************************************************************/
  544.  
  545. void free_tile(void)
  546. {
  547.  int a;
  548.  
  549.  for (a=0;a<TILES;a++)
  550.   if (tile[a]!=NULL) hfree(tile[a]);
  551.  
  552.  if (tile!=NULL) hfree(tile);
  553. }
  554.  
  555. /****************************************************************************/
  556. /****************************************************************************/
  557. /****************************************************************************/
  558.  
  559. byte allocate_memory(void)
  560. {
  561.  if (allocate_screen()==FAILURE) return(FAILURE);
  562.  if (allocate_font()==FAILURE) return(FAILURE);
  563.  if (allocate_tile()==FAILURE) return(FAILURE);
  564.  if (allocate_mouse()==FAILURE) return(FAILURE);
  565.  if ((object_background=(byte huge *)halloc(256L,1))==NULL) return(FAILURE);
  566.  return(SUCCESS);
  567. }
  568.  
  569. /****************************************************************************/
  570. /****************************************************************************/
  571. /****************************************************************************/
  572.  
  573. void free_memory(void)
  574. {
  575.  free_mouse();
  576.  free_tile();
  577.  free_font();
  578.  free_screen();
  579.  if (object_background!=NULL) hfree(object_background);
  580. }
  581.  
  582. /****************************************************************************/
  583. /****************************************************************************/
  584. /****************************************************************************/
  585.  
  586. void init_mouse(void)
  587. {
  588.  byte tmp[]={1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  589.          1,7,1,0,0,0,0,0,0,0,0,0,0,0,0,0,
  590.          1,7,7,1,0,0,0,0,0,0,0,0,0,0,0,0,
  591.          1,7,7,7,1,0,0,0,0,0,0,0,0,0,0,0,
  592.          1,7,7,7,7,1,0,0,0,0,0,0,0,0,0,0,
  593.          1,7,7,7,7,7,1,0,0,0,0,0,0,0,0,0,
  594.          1,7,7,7,7,7,7,1,0,0,0,0,0,0,0,0,
  595.          1,7,7,7,7,7,7,7,1,0,0,0,0,0,0,0,
  596.          1,7,7,7,7,7,7,7,7,1,0,0,0,0,0,0,
  597.          1,7,7,7,7,7,7,7,7,7,1,0,0,0,0,0,
  598.          1,7,7,7,7,7,7,7,7,7,7,1,0,0,0,0,
  599.          1,7,7,7,7,1,1,1,1,1,1,0,0,0,0,0,
  600.          1,7,7,7,1,0,0,0,0,0,0,0,0,0,0,0,
  601.          1,7,7,1,0,0,0,0,0,0,0,0,0,0,0,0,
  602.          1,7,1,0,0,0,0,0,0,0,0,0,0,0,0,0,
  603.          1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  604.  memcpy(mouse_cursor,tmp,256);
  605.  read_mouse();
  606.  update_mouse();
  607. }
  608.  
  609. /****************************************************************************/
  610. /****************************************************************************/
  611. /****************************************************************************/
  612.  
  613. byte tile_color(byte current_tile,int x, int y)
  614. {
  615.  return(tile[current_tile][y*TILE_X+x]);
  616. }
  617.  
  618. /****************************************************************************/
  619. /****************************************************************************/
  620. /****************************************************************************/
  621.  
  622. void update_tile_grid(byte current_tile)
  623. {
  624.  int a, b;
  625.  
  626.  for (b=0;b<16;b++)
  627.  {
  628.   for (a=0;a<16;a++)
  629.   {
  630.    box(FILL,a*8+6,b*8+6,a*8+10,b*8+9,tile[current_tile][b*TILE_X+a]);
  631.   }
  632.  }
  633. }
  634.  
  635. /****************************************************************************/
  636. /****************************************************************************/
  637. /****************************************************************************/
  638.  
  639. void update_tile(int x, int y, byte current_tile, byte current_color)
  640. {
  641.  tile[current_tile][y*TILE_X+x]=current_color;
  642.  box(FILL,x*8+6,y*8+6,x*8+10,y*8+9,current_color);
  643. }
  644.  
  645. /****************************************************************************/
  646. /****************************************************************************/
  647. /****************************************************************************/
  648.  
  649. void update_tile_display(byte current_tile, byte current_page)
  650. {
  651.  int a, b;
  652.  
  653.  for (a=0;a<7;a++)
  654.   put_image(195+a*16,180,tile[(byte)(current_page+a)],TILE_X,TILE_Y,NORMAL);
  655.  
  656.  if (current_tile>=current_page && current_tile<(word)(current_page+7))
  657.   box(BORDER,195+(current_tile-current_page)*16,180,
  658.          195+(current_tile-current_page)*16+TILE_X-1,180+TILE_Y-1,7);
  659.  
  660.  for (b=0;b<8;b++)
  661.  {
  662.   for (a=0;a<8;a++)
  663.   {
  664.    put_image(188+a*16,4+b*16,tile[map[b*8+a]],TILE_X,TILE_Y,NORMAL);
  665.   }
  666.  }
  667.  
  668.  put_string(160,12,"   ",4,INVERSE);
  669.  put_number_i(160,12,current_tile,7,NORMAL);
  670. }
  671.  
  672. /****************************************************************************/
  673. /****************************************************************************/
  674. /****************************************************************************/
  675.  
  676. void hide_cursor(byte current_tile, int x, int y)
  677. {
  678.  box(FILL,x*8+6,y*8+6,x*8+10,y*8+10,tile[current_tile][y*TILE_X+x]);
  679.  box(BORDER,x*8+5,y*8+5,x*8+11,y*8+11,0);
  680. }
  681.  
  682. /****************************************************************************/
  683. /****************************************************************************/
  684. /****************************************************************************/
  685.  
  686. void show_cursor(byte current_tile, int x, int y)
  687. {
  688.  box(BORDER,x*8+5,y*8+5,x*8+11,y*8+11,7);
  689. }
  690.  
  691. /****************************************************************************/
  692. /****************************************************************************/
  693. /****************************************************************************/
  694.  
  695. void hide_color(byte current_color)
  696. {
  697.  int x=(current_color-(current_color/32)*32)*4+4,
  698.      y=(current_color/32)*8+136;
  699.  box(BORDER,x,y,x+3,y+7,75);
  700. }
  701.  
  702. /****************************************************************************/
  703. /****************************************************************************/
  704. /****************************************************************************/
  705.  
  706. void show_color(byte current_color)
  707. {
  708.  int x=(current_color-(current_color/32)*32)*4+4,
  709.      y=(current_color/32)*8+136;
  710.  box(BORDER,x,y,x+3,y+7,7);
  711. }
  712.  
  713. /****************************************************************************/
  714. /****************************************************************************/
  715. /****************************************************************************/
  716.  
  717. void show_palette_information(byte current_color)
  718. {
  719.  byte red=palette[current_color*3+0],
  720.       green=palette[current_color*3+1],
  721.       blue=palette[current_color*3+2];
  722.  
  723.  box(FILL,142,135,149,197,0);
  724.  box(FILL,156,135,163,197,0);
  725.  box(FILL,170,135,177,197,0);
  726.  
  727.  if (red>0) box(FILL,142,198-red,149,197,15);
  728.  if (green>0) box(FILL,156,198-green,163,197,23);
  729.  if (blue>0) box(FILL,170,198-blue,177,197,31);
  730. }
  731.  
  732. /****************************************************************************/
  733. /****************************************************************************/
  734. /****************************************************************************/
  735.  
  736. void hide_object(void)
  737. {
  738.  put_image(mouse_x,mouse_y,object_background,TILE_X,TILE_Y,NORMAL);
  739. }
  740.  
  741. /****************************************************************************/
  742. /****************************************************************************/
  743. /****************************************************************************/
  744.  
  745. void show_object(byte object_carried)
  746. {
  747.  get_image(mouse_x,mouse_y,object_background,TILE_X,TILE_Y);
  748.  put_image(mouse_x,mouse_y,tile[object_carried],TILE_X,TILE_Y,MASK);
  749. }
  750.  
  751. /****************************************************************************/
  752. /****************************************************************************/
  753. /****************************************************************************/
  754.  
  755. byte load(char *filename)
  756. {
  757.  FILE *file;
  758.  size_t bytes_read;
  759.  char buf[80];
  760.  int a;
  761.  
  762.  sprintf(buf,"%s%s.til",path,filename);
  763.  
  764.  file=fopen(buf,"rb");
  765.  if (file==NULL) return(FAILURE);
  766.  
  767.  for (a=0;a<256;a++)
  768.   bytes_read=fread(tile[a],1,256,file);
  769.  
  770.  sprintf(buf,"%s%s.dat",path,map_file);
  771.  file=fopen(buf,"rb");
  772.  if (file!=NULL)
  773.  {
  774.   bytes_read=fread(map,1,64,file);
  775.   fclose(file);
  776.  }
  777.  
  778.  fclose(file);
  779.  return(SUCCESS);
  780. }
  781.  
  782. /****************************************************************************/
  783. /****************************************************************************/
  784. /****************************************************************************/
  785.  
  786. byte save(char *filename)
  787. {
  788.  FILE *file;
  789.  size_t bytes_written;
  790.  char buf[80];
  791.  int a;
  792.  
  793.  sprintf(buf,"%s%s.til",path,filename);
  794.  
  795.  file=fopen(buf,"wb");
  796.  if (file==NULL) return(FAILURE);
  797.  
  798.  for (a=0;a<256;a++)
  799.   bytes_written=fwrite(tile[a],1,256,file);
  800.  
  801.  fclose(file);
  802.  
  803.  sprintf(buf,"%s%s.dat",path,map_file);
  804.  file=fopen(buf,"wb");
  805.  if (file!=NULL)
  806.  {
  807.   bytes_written=fwrite(map,1,64,file);
  808.   fclose(file);
  809.  }
  810.  
  811.  return(SUCCESS);
  812. }
  813.  
  814. /****************************************************************************/
  815. /****************************************************************************/
  816. /****************************************************************************/
  817.  
  818. void hflip(byte current_tile)
  819. {
  820.  byte tmp[256];
  821.  int a, b;
  822.  
  823.  for (a=0;a<16;a++)
  824.  {
  825.   for (b=0;b<16;b++)
  826.    tmp[b*TILE_X+a]=tile[current_tile][b*TILE_X+(TILE_X-1-a)];
  827.  }
  828.  memcpy(tile[current_tile],tmp,TILE_X*TILE_Y);
  829. }
  830.  
  831. /****************************************************************************/
  832. /****************************************************************************/
  833. /****************************************************************************/
  834.  
  835. void vflip(byte current_tile)
  836. {
  837.  byte tmp[256];
  838.  int a, b;
  839.  
  840.  for (b=0;b<16;b++)
  841.  {
  842.   for (a=0;a<16;a++)
  843.    tmp[b*TILE_X+a]=tile[current_tile][(TILE_Y-1-b)*TILE_X+a];
  844.  }
  845.  memcpy(tile[current_tile],tmp,TILE_X*TILE_Y);
  846. }
  847.  
  848. /****************************************************************************/
  849. /****************************************************************************/
  850. /****************************************************************************/
  851.  
  852. void rotate(byte current_tile)
  853. {
  854.  byte tmp[256];
  855.  int a, b;
  856.  
  857.  for (a=0;a<16;a++)
  858.  {
  859.   for (b=0;b<16;b++)
  860.    tmp[b*TILE_X+a]=tile[current_tile][(TILE_Y-1-a)*TILE_X+b];
  861.  }
  862.  memcpy(tile[current_tile],tmp,TILE_X*TILE_Y);
  863. }
  864.  
  865. /****************************************************************************/
  866. /****************************************************************************/
  867. /****************************************************************************/
  868.  
  869. /****************************************************************************/
  870. /****************************************************************************/
  871. /****************************************************************************/
  872.  
  873.  
  874.